﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using TopUpService.AOP;
using TopUpService.AOP.Aspects;

namespace Vjezbe2
{
    public class TopUpService : ITopUpService
    {
        private ITopUpDataService dataService;
        public TopUpService(ITopUpDataService dataService)
        {
            this.dataService = dataService;
        }

        [NotNullArgumentAspect(AspectPriority = 0)]
        [LoggingAspect(AspectPriority = 1)]
        [ExceptionHandlerAspect(AspectPriority = 2)]
        [TransactionWithRetryAspect(AspectPriority = 3)]
        public void TopUp(TopUpRequest request)
        {
            // poslovna logika
			int amount = request.Amount;

			if (amount <= 50)
			{
				amount += 10;
			}
			else
			{
				amount += 20;
			}

			dataService.AddAmount(request.AccountId, amount);
        }
    }
}
